package com.milk.web;

import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.dubbo.annotation.AutowiredDubbo;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lorne.tx.annotation.TxTransaction;
import com.milk.model.entity.admin.Admin;
import com.milk.model.entity.admin.Function;
import com.milk.service.Demo2Service;
import com.milk.service.DemoService;
import com.milk.service.admin.AdminService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
public class DemoController {
	
	private Logger log = LoggerFactory.getLogger(this.getClass());

	@AutowiredDubbo(retries=0,timeout=3000,check=false,mock="true")
	private DemoService demoService;
	
	@AutowiredDubbo(check=false)
	private Demo2Service demo2Service;
	
	@AutowiredDubbo(check=false)
	private AdminService adminService;
	
	@Autowired
	private StringRedisTemplate stringRedisTemplate;
    
	@ApiOperation(value="测试",notes="测试一个hello方法，传入参数返回hello {params}！")
	@ApiImplicitParam(dataType="java.lang.String",name="name",value="name",required=true,paramType="query")
    @RequestMapping("/hello")
	@TxTransaction
    public String hello(String name){
		
		//stringRedisTemplate.opsForValue().set("hello", "开始", 30, TimeUnit.SECONDS);
		
		long start = System.currentTimeMillis();
		Function f = new Function();
		f.setUrl("asd");
		adminService.saveFunction(f);
		Admin admin = new Admin();
		admin.setUsername("lcn");
		admin.setPassword("lcn");
		adminService.save(admin);
		
		int result = 100/0;
		
		//String result = demoService.sayHello();

		
    	return "耗时："+(System.currentTimeMillis() - start);
    }
	
	@RequestMapping("/bye")
    public String bye(){
    	return demo2Service.sayBye();
    }
}
